<?php

class Core_AdminSettingsController extends Zend_Controller_Action
{

	public function init()
	{

	}

	public function indexAction()
	{
	}

	public function infoAction()
	{
		ob_start();
		phpinfo();
		$source = ob_get_clean();

		preg_match('~<style.+?>(.+?)</style>.+?(<table.+\/table>)~ims', $source, $matches);
		$css = $matches[1];
		$source = $matches[2];

		$css = preg_replace('/[\r\n](.+?{)/iu', "\n#phpinfo \$1", $css);

		//$regex = '/'.preg_quote('<a href="http://www.php.net/">',
		// '/').'.+?'.preg_quote('</a>', '/').'/ims';
		//$source = preg_replace($regex, '', $source);

		// strip images from phpinfo()
		$regex = '/<img .+?>/ims';
		$source = preg_replace($regex, '', $source);

		$regex = '/' . preg_quote('<h2>PHP License</h2>', '/') . '.+$/ims';
		$source = preg_replace($regex, '', $source);

		$source = str_replace("module_Zend Optimizer", "module_Zend_Optimizer", $source);

		$this -> view -> style = $css;
		$this -> view -> content = $source;

	}

	public function siteInfoAction()
	{
		$form = $this -> view -> form = new Core_Form_Admin_Settings_SiteInfo;
		$req = $this -> getRequest();
		if ($req -> isGet())
		{
			$form -> populateSetting();
		}

		if ($req -> isPost() && $form -> isValid($req -> getPost()))
		{
			$form -> commitSetting();
		}
	}

	public function mailAction()
	{
		$form = $this -> view -> form = new Core_Form_Admin_Settings_Mail;

		$req = $this -> getRequest();
		if ($req -> isGet())
		{
			$form -> populateSetting();
		}

		if ($req -> isPost() && $form -> isValid($req -> getPost()))
		{
			$form -> commitSetting();
		}

	}

	public function cacheAction()
	{
		$form = $this -> view -> form = new Core_Form_Admin_Settings_Cache;
		$req = $this -> getRequest();
		if ($req -> isGet())
		{
			$form -> populateSetting();
		}

		if ($req -> isPost() && $form -> isValid($req -> getPost()))
		{
			$form -> commitSetting();
		}
	}
    
    public function socialAction(){
        $form = $this -> view -> form = new Core_Form_Admin_Settings_Social;
        $req = $this -> getRequest();
        if ($req -> isGet())
        {
            $form -> populateSetting();
        }

        if ($req -> isPost() && $form -> isValid($req -> getPost()))
        {
            $form -> commitSetting();
        }
    }
    
    public function utilityAction(){
        $form = $this -> view -> form = new Core_Form_Admin_Settings_Utility;
        $req = $this -> getRequest();
        if ($req -> isGet())
        {
            $form -> populateSetting();
        }

        if ($req -> isPost() && $form -> isValid($req -> getPost()))
        {
            $form -> commitSetting();
        }
    }
	
	// configure regional and languages
    public function regionalLanguageAction(){
        $form = $this -> view -> form = new Core_Form_Admin_Settings_RegionalLanguage;
        $req = $this -> getRequest();
        if ($req -> isGet())
        {
            $form -> populateSetting();
        }

        if ($req -> isPost() && $form -> isValid($req -> getPost()))
        {
            $form -> commitSetting();
        }
    }
	
	// configure date & time format
    public function datetimeAction(){
        $form = $this -> view -> form = new Core_Form_Admin_Settings_Datetime;
        $req = $this -> getRequest();
        if ($req -> isGet())
        {
            $form -> populateSetting();
        }

        if ($req -> isPost() && $form -> isValid($req -> getPost()))
        {
            $form -> commitSetting();
        }
    }
	
	// configure currency settings
    public function currencyAction(){
        $form = $this -> view -> form = new Core_Form_Admin_Settings_Currency;
        $req = $this -> getRequest();
        if ($req -> isGet())
        {
            $form -> populateSetting();
        }

        if ($req -> isPost() && $form -> isValid($req -> getPost()))
        {
            $form -> commitSetting();
        }
    }
	
	// configure maintenance settings
    public function maintenanceAction(){
        $form = $this -> view -> form = new Core_Form_Admin_Settings_Maintenance;
        $req = $this -> getRequest();
        if ($req -> isGet())
        {
            $form -> populateSetting();
        }

        if ($req -> isPost() && $form -> isValid($req -> getPost()))
        {
            $form -> commitSetting();
        }
    }
	
	// editor settings
    public function editorAction(){
        $form = $this -> view -> form = new Core_Form_Admin_Settings_Editor;
        $req = $this -> getRequest();
        if ($req -> isGet())
        {
            $form -> populateSetting();
        }

        if ($req -> isPost() && $form -> isValid($req -> getPost()))
        {
            $form -> commitSetting();
        }
    }
	
	// editor settings
    public function signupAction(){
        $form = $this -> view -> form = new Core_Form_Admin_Settings_Signup;
        $req = $this -> getRequest();
        if ($req -> isGet())
        {
            $form -> populateSetting();
        }

        if ($req -> isPost() && $form -> isValid($req -> getPost()))
        {
            $form -> commitSetting();
        }
    }
}
